CPUS=$(shell nproc)

all:
	@echo 无事可做

# make package starter 将打包星火商店投稿器(启动器)
# spark-store-submitter-starter_0.1-20230203_amd64.deb

CALENDAR=$(shell date '+%Y%m%d')
OSID=$(shell lsb_release -si)
OSRELEASE=$(shell lsb_release -sr)
SUFFIX=
ifneq ("$(OSID)", "")
SUFFIX=_$(OSID)$(OSRELEASE)
endif
PACKAGE_NAME=spark-store-submitter-starter

package-starter:
	mkdir -p build
	cd build && cmake ../tools/spark-store-submitter-starter -DPACKAGE_SUFFIX="$(SUFFIX)" ..
	cd build && make package
	tree build/_CPack_Packages/Linux/DEB/$(PACKAGE_NAME)-*
	dpkg-deb --contents build/$(PACKAGE_NAME)_*$(CALENDAR)*$(SUFFIX).deb

copytosource: package-starter
	cp build/$(PACKAGE_NAME)_*$(CALENDAR)*.deb .


# make ... 构建 SparkStoreSubimtter 与相关内容
PROJECT_NAME=SparkStoreSubmitter
PROJECT_VERSION=$(shell cat VERSION)

run: pyuic
	@echo "是否存在 resource.qrc? 是否已经使用 make pyrcc 生成?" 
	@echo "正在运行."
	@/usr/bin/python3 $(PROJECT_NAME)

run-test:
	/usr/bin/python3 tests/testBaseQtAnimationMoveCenter.py
	/usr/bin/python3 tests/testBaseQtMoveCenterInDesktopWidget.py
	/usr/bin/python3 tests/testCircleMath.py
	/usr/bin/python3 tests/testCustomeProgressBarWidget.py
	/usr/bin/python3 tests/testIcon.py
	/usr/bin/python3 tests/testMath.py
	/usr/bin/python3 tests/testProgress.py

clean:
	/usr/bin/py3clean .

# 判断 pipreqs 是否存在，存在即可使用 pipreqs 进行导出 requirements.txt
PIPREQS="$(shell which pipreqs)"
ifneq ($(PIPREQS), "")
requirements-export:
	@echo "正在导出 requirements.txt"
	@pipreqs

requirements-export--force:
	@echo "正在导出 requirements.txt(使用 --force 参数覆盖)"
	@pipreqs --force

else
requirements:
	@echo "您是否未安装 pipreqs? 请使用以下命令来安装(否则请查看 Makefile):"
	@echo "    python3 -m pip install pipreqs"

endif

################### 添加的其它操作(用于处理 pyuic 内容) ###################
# 是否应该将例如 mainwindow.ui > ui_mainwindow.py? 也许比较符合 Qt 规范。

mainwindow:
	test $(PROJECT_NAME)/mainwindow.ui && pyuic5 $(PROJECT_NAME)/mainwindow.ui > $(PROJECT_NAME)/ui_mainwindow.py

test-mainwindow:
	test tests/mainwindow.ui && pyuic5 tests/mainwindow.ui > tests/ui_mainwindow.py

test-customeProgressbar:
	pyuic5 tests/progressbar.ui > tests/ui_progressbar.py

test-widgetshake:
	pyuic5 tests/widgetshake.ui > tests/ui_widgetshake.py

test-bubblewidget-mainwindow:
	pyuic5 tests/BubbleWidget/mainwindow.ui > tests/BubbleWidget/ui_mainwindow.py

pyuic: mainwindow test-mainwindow test-customeProgressbar test-widgetshake test-bubblewidget-mainwindow
	@echo "处理完成"
	
################### 添加的其它操作(用于处理 pyrcc 内容) ###################
pyrcc:
	pyrcc5 resources.qrc -o $(PROJECT_NAME)/resources.py

################### 添加的其它操作(构建打包，安装?) ###################

# make dist 将进行构建 whl 文件与代码包
dist: dist-clean
	@echo "Build started"
	python3 ./setup.py sdist bdist_wheel

# make install 将安装到系统(建议使用sudo)
install:
	python3 ./setup.py install

# make install-whl 将安装 all 编译出的分发包
install-whl: 
	python3 -m pip install ./dist/$(PROJECT_NAME)-$(PROJECT_VERSION)-py3-none-any.whl

# make clean 将进行清空一些产生的文件
dist-clean: 
	rm -rf dist build $(PROJECT_NAME).egg-info

